package com.study.factory.impl;

import com.study.factory.Payment;

/**
 * 支付工厂
 */
public class PaymentFactory {

    private static volatile PaymentFactory instance;

    private PaymentFactory() {
    }

    public static PaymentFactory  getInstance() {
        if (instance == null) {
            synchronized (PaymentFactory .class) {
                if (instance == null) {
                    instance = new PaymentFactory ();
                }
            }
        }
        return instance;
    }



    public   Payment payment(Integer type) {
        if(1 != type && 2 != type) {
            throw new IllegalArgumentException("支付类型错误");
        }
        if (type.equals(1)) {
            return new AliaPay();
        }
        if (type.equals(2)) {
            return new AliaPay();
        }
        return null;
    }

}
